package cc.linker.steplink.crm.merchanth5.service.impl;

import cc.linker.steplink.crm.commons.TradeTypeConstants;
import cc.linker.steplink.crm.merchanth5.dao.acs.ProtectRecordDao;
import cc.linker.steplink.crm.merchanth5.dao.acs.PurchaseProcessDao;
import cc.linker.steplink.crm.merchanth5.pojo.acs.ProtectPo;
import cc.linker.steplink.crm.merchanth5.service.acs.ProtectRecordService;
import cc.linker.steplink.crm.response.GlobalException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class ProtectRecordServiceImpl implements ProtectRecordService {

    @Autowired
    private ProtectRecordDao protectRecordDao;
    @Autowired
    private PurchaseProcessDao purchaseProcessDao;
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    /**
     * @Description: 插入结算中心退款账单
     * @Param: orderSn 订单号
     * @Param: recId 订单商品表索引
     * @Param: goodsPrice 商品单价（单位：分，默认0）
     * @Param: goodsNum 商品数量（单位：分，默认0）
     * @Param: shippingFee 商品运费（单位：分，默认0）
     */
    @Override
    public void addRefund(String orderSn, Long recId, Long goodsPrice, Long goodsNum, Long shippingFee) {
        //查询是否有该recId的退款中记录
//        Long recIdRefundCount= protectRecordDao.recIdRefundCount(recId);
//        if(recIdRefundCount>0){
//            LOGGER.info("recIdRefundCount为"+recIdRefundCount+"存在正在退款的记录,不要重复退款!!!");
//            LOGGER.info("recId为"+recId+"存在正在退款的记录,不要重复退款！");
//            throw GlobalException.build("recId为"+recId+"存在正在退款的记录，不要重复退款！");
//        }
        //新表是否有数据（后面可以去掉）
        Integer protectGoodsCount = purchaseProcessDao.getProtectGoodsCount(orderSn);
        List<ProtectPo> endProtectList;
        if (protectGoodsCount == 0) {
            //老逻辑退款
            endProtectList = this.addOldRecord(orderSn, goodsPrice, goodsNum, shippingFee);
        } else {
            //新逻辑退款
            endProtectList = this.addNewRecord(recId);
        }

        //插入表
        if (endProtectList != null && endProtectList.size() > 0) {
            for (ProtectPo endProtect : endProtectList) {
                endProtect.setRecId(recId);
                endProtect.setOrderName("退款");
                if (endProtect.getAmount() != null && endProtect.getAmount() > 0) {
                    protectRecordDao.addRefund(endProtect);
                }
            }
            Map map = new HashMap();
            map.put("orderSn", orderSn);
            map.put("endTime", null);
            protectRecordDao.setEndTime(map);
            protectRecordDao.setOrderEndTime(map);
        }
    }

    @Override
    public List<ProtectPo> addNewRecord(Long recId) {
        return protectRecordDao.getRecProtectPoList(recId);
    }

    @Override
    public List<ProtectPo> addOldRecord(String orderSn, Long goodsPrice, Long goodsNum, Long shippingFee) {
        Long refundAmunt = goodsPrice * goodsNum + shippingFee;
        //算出支付总金额（包含金币）
        Long allamount = protectRecordDao.getAllAmount(orderSn);
        List<ProtectPo> endProtectList = new ArrayList<ProtectPo>();

        if (allamount <= refundAmunt) {
            //如果退款金额等于购买金额（全部退款）
            //获取支付所有记录
            endProtectList = protectRecordDao.getInProtectPoListNo(orderSn);
        } else if (allamount < refundAmunt) {
            LOGGER.info("退款金额超过订单总金额");
            throw GlobalException.build("退款金额超过订单总金额");
        } else {
            //部分退款
            //算出之前退款总金额（包含金币）
            Long allrefundamount = protectRecordDao.getAllRefundAmount(orderSn);
            //如果退款金额大于等于购买金额减之前的退款（全部退款）(大于是之前存在进位误差)
            if ((allamount - allrefundamount) <= refundAmunt) {
                //最终插入汇总表记录
                endProtectList = refundOrder(orderSn);
            } else if ((allamount - allrefundamount) > refundAmunt) {
                //如果退款金额小于购买金额减之前的退款（部分退款）
                //计算手续费比例
                Map<String, String> map = protectRecordDao.getTake(orderSn);
                double linkerTake = 0;
                double unionbarleyTake = 0;
                if (map != null) {
                    linkerTake = (Double.valueOf(map.get("linkerTake"))) / 100;
                    unionbarleyTake = (Double.valueOf(map.get("unionbarleyTake"))) / 100;
                }

                //之前退款总金币
                Long refundamountScore = 0l;
                //linker退款手续费
                long linkerTakeAmount = 0l;
                //大b退款手续费
                long unionbarleyTakeAmount = 0l;
                //退款金币
                long thisScore = 0l;
                //算出支付总金额（不包含金币）
                Long amount = protectRecordDao.getAmount(orderSn);
                //算出之前退款总金额（不包含金币）
                Long refundamount = protectRecordDao.getRefundAmount(orderSn);
                //算出支付总金币
                Long amountScore = protectRecordDao.getAmountScore(orderSn);
                if (amountScore > 0) {
                    refundamountScore = protectRecordDao.getRefundAmountScore(orderSn);
                    //按比例计算本次需要退款的金币
                    thisScore = new BigDecimal(((double) (amountScore * refundAmunt)) / allamount).setScale(0, BigDecimal.ROUND_HALF_EVEN).longValue();
                    if (thisScore > (amountScore - refundamountScore)) {
                        thisScore = amountScore - refundamountScore;
                    }
                }
                if (linkerTake > 0) {
                    //所有支付手续费(Linker)
                    Long inProceduresL = protectRecordDao.getInProceduresL(orderSn);
                    //所有退款手续费（Linker）
                    Long outProceduresL = protectRecordDao.getOutProceduresL(orderSn);
                    linkerTakeAmount = new BigDecimal((refundAmunt - thisScore) * linkerTake).setScale(0, BigDecimal.ROUND_HALF_EVEN).longValue();
                    if ((inProceduresL - outProceduresL) < linkerTakeAmount) {
                        linkerTakeAmount = inProceduresL - outProceduresL;
                    }
                }
                if (unionbarleyTake > 0) {
                    //所有支付手续费(大b)
                    Long inProceduresB = protectRecordDao.getInProceduresB(orderSn);
                    //所有退款手续费（大b）
                    Long outProceduresB = protectRecordDao.getOutProceduresB(orderSn);
                    unionbarleyTakeAmount = new BigDecimal((refundAmunt - thisScore) * unionbarleyTake).setScale(0, BigDecimal.ROUND_HALF_EVEN).longValue();
                    if ((inProceduresB - unionbarleyTakeAmount) < unionbarleyTakeAmount) {
                        unionbarleyTakeAmount = inProceduresB - unionbarleyTakeAmount;
                    }
                }
                //获取支付所有记录
                List<ProtectPo> inProtectList = protectRecordDao.getInProtectPoListInTime(orderSn);
                for (ProtectPo inProtect : inProtectList) {
                    if (inProtect.getType() != null && inProtect.getType() == 9) {
                        inProtect.setAmount(linkerTakeAmount);
                    } else if (inProtect.getType() != null && inProtect.getType() == 4) {
                        inProtect.setAmount(unionbarleyTakeAmount);
                    } else if (inProtect.getType() != null && inProtect.getType() == 10 && inProtect.getAmountType() != null && inProtect.getAmountType() == 1) {
                        inProtect.setAmount((refundAmunt - thisScore - linkerTakeAmount - unionbarleyTakeAmount));
                    } else if (inProtect.getAmountType() != null && inProtect.getAmountType() == 2) {
                        inProtect.setAmount(thisScore);
                    }
                }
                endProtectList = inProtectList;
            }
        }
        return endProtectList;
    }

    /**
     * 根据订单号返回退款列表
     */
    @Override
    public List<ProtectPo> refundOrder(String orderSn) {
        //获取支付列表
        List<ProtectPo> inProtectList = protectRecordDao.getInProtectPoListInTime(orderSn);
        //获取退款列表
        List<ProtectPo> outProtectList = protectRecordDao.getOutProtectPoListInTime(orderSn);
        //最终插入汇总表记录
        List<ProtectPo> endProtectList = reduceList(inProtectList, outProtectList);

        return endProtectList;
    }

    /**
     * 查询完结订单号
     */
    @Override
    public List<String> getOrderSnList() {
        return protectRecordDao.getOrderSnList();
    }

    /**
     * 根据订单号进行结算
     */
    @Override
    public List<ProtectPo> settleOrder(String orderSn) {
        //获取支付列表
        List<ProtectPo> inProtectList = protectRecordDao.getInProtectPoList(orderSn);
        //获取退款列表
        List<ProtectPo> outProtectList = protectRecordDao.getOutProtectPoList(orderSn);
        //最终插入汇总表记录
        List<ProtectPo> endProtectList = settelreduceList(inProtectList, outProtectList);

        return endProtectList;
    }

    @Override
    public List<ProtectPo> reduceList(List<ProtectPo> inProtectList, List<ProtectPo> outProtectList) {
        List<ProtectPo> endProtectList = new ArrayList<ProtectPo>();
        for (ProtectPo inProtect : inProtectList) {
            for (ProtectPo outProtect : outProtectList) {
                //如果类型相同、收款用户与付款用户相同并且金额类型也相同，则进行汇总
                if (inProtect.getType() != null && outProtect.getType() != null && inProtect.getType() == outProtect.getType()
                        && inProtect.getReceiveUser() != null && outProtect.getPayUser() != null && inProtect.getReceiveUser().equals(outProtect.getPayUser())
                        && inProtect.getAmountType() != null && outProtect.getAmountType() != null && inProtect.getAmountType().equals(outProtect.getAmountType())) {
                    Long inAmount = (inProtect.getAmount() == null ? 0l : inProtect.getAmount());
                    Long outAmount = (outProtect.getAmount() == null ? 0l : outProtect.getAmount());
                    Long endAmount = inAmount - outAmount;
                    inProtect.setAmount(endAmount);
                }
            }
            if (inProtect.getAmount() != null && inProtect.getAmount() > 0) {
                endProtectList.add(inProtect);
            }
        }
        return endProtectList;
    }

    @Override
    public List<ProtectPo> settelreduceList(List<ProtectPo> inProtectList, List<ProtectPo> outProtectList) {
        List<ProtectPo> endProtectList = new ArrayList<ProtectPo>();
        for (ProtectPo inProtect : inProtectList) {
            for (ProtectPo outProtect : outProtectList) {
                if (inProtect.getType() != null && outProtect.getType() != null
                        && (inProtect.getType() != 2 && inProtect.getType() != 3 && outProtect.getType() != 2 && outProtect.getType() != 3)
                ) {
                    //如果类型相同、收款用户与付款用户相同并且金额类型也相同，则进行汇总
                    if (inProtect.getType() != null && outProtect.getType() != null && inProtect.getType().equals(outProtect.getType())
                            && inProtect.getReceiveUser() != null && outProtect.getPayUser() != null && inProtect.getReceiveUser().equals(outProtect.getPayUser())
                            && inProtect.getAmountType() != null && outProtect.getAmountType() != null && inProtect.getAmountType().equals(outProtect.getAmountType())
                    ) {
                        if (inProtect.getAmountType() == 1) {
                            Long inAmount = (inProtect.getAmount() == null ? 0L : inProtect.getAmount());
                            Long outAmount = (outProtect.getAmount() == null ? 0L : outProtect.getAmount());
                            Long endAmount = inAmount - outAmount;
                            inProtect.setAmount(endAmount);
                        } else if (inProtect.getAmountType() == 2 && inProtect.getType() == 1) {
                            //金币的服务费
                            if (inProtect.getRecId() != null && outProtect.getRecId() != null && inProtect.getRecId().equals(outProtect.getRecId())) {
                                Long inAmount = (inProtect.getAmount() == null ? 0L : inProtect.getAmount());
                                Long outAmount = (outProtect.getAmount() == null ? 0L : outProtect.getAmount());
                                Long endAmount = inAmount - outAmount;
                                inProtect.setAmount(endAmount);
                            }
                        }

                    }
                } else if (inProtect.getType() != null && outProtect.getType() != null
                        && (inProtect.getType() == 2 || inProtect.getType() == 3 || outProtect.getType() == 2 || outProtect.getType() == 3)) {
                    if (inProtect.getType() != null && outProtect.getType() != null && inProtect.getType().equals(outProtect.getType())
                            && inProtect.getReceiveUser() != null && outProtect.getPayUser() != null && inProtect.getReceiveUser().equals(outProtect.getPayUser())
                            && inProtect.getAmountType() != null && outProtect.getAmountType() != null && inProtect.getAmountType().equals(outProtect.getAmountType())
                            && inProtect.getRecId() != null && outProtect.getRecId() != null && inProtect.getRecId().equals(outProtect.getRecId())
                    ) {
                        Long inAmount = (inProtect.getAmount() == null ? 0L : inProtect.getAmount());
                        Long outAmount = (outProtect.getAmount() == null ? 0L : outProtect.getAmount());
                        Long endAmount = inAmount - outAmount;
                        inProtect.setAmount(endAmount);
                    }
                }

            }
            if (inProtect.getAmount() != null && inProtect.getAmount() > 0) {
                endProtectList.add(inProtect);
            }
        }
        //全金币抵扣，且不是全额退款（插入为0的记录）
//        for( ProtectPo inProtect : inProtectList){
//            Long otherAmount = 0L;
//            if(inProtect.getAmount()!=null && inProtect.getAmount()==0 && inProtect.getType() != null && (inProtect.getType() == 1 || inProtect.getType() == 10)){
//                for( ProtectPo otherProtect : inProtectList){
//                    if(!inProtect.getId().equals(otherProtect.getId()) && inProtect.getOrderSn().equals(otherProtect.getOrderSn())){
//                        if(otherProtect.getAmount()!=null){
//                            otherAmount = otherAmount + otherProtect.getAmount();
//                        }
//                    }
//                }
//            }
//            if(otherAmount>0){
//                endProtectList.add(inProtect);
//            }
//        }
        return endProtectList;
    }

    /**
     * 合并完成后插入老表
     */
    @Override
    public void insertOldTrder(List<ProtectPo> protectList) {
        for (ProtectPo protect : protectList) {
            //获取收款用户余额
            String to = protect.getReceiveUser();
            Integer receiveRole = protect.getReceiveRole();
            Integer balance;
            //1是现金 2 金币
            if (protect.getAmountType() != null && protect.getAmountType() == 1) {
                switch (receiveRole) {
                    // 根据收款人角色，判断给哪个表加，在哪个表查余额。
                    // 先加，再取余额，再记录
                    case 0:
                        balance = 0;
                        break;
                    case 1:
                        // 大b
                        balance = purchaseProcessDao.getOrgBalanceByOrgId(to);
                        break;
                    case 2:
                        // 小b
                        balance = purchaseProcessDao.getSalesBalanceByCustomerId(to);
                        break;
                    case 3:
                    case 4:
                    case 5:
                        // 普通用户
                        balance = purchaseProcessDao.getUserBalanceByCustomerId(to);
                        break;
                    default:
                        balance = 0;
                        break;
                }
                if (balance == null) {
                    balance = 0;
                }
                protect.setReceiveAccountBalance(balance.longValue());
                //插入t_crm_acs_account_trade
                protectRecordDao.insertOld(protect);
            } else if (protect.getAmountType() != null && protect.getAmountType() == 2) {
                //获取收款用户积分
                //插入t_crm_acs_account_trade_score
                if (protect.getType() != null && protect.getType() != 0) {
                    balance = purchaseProcessDao.getCustomerScoreBalanceByCustomerId(to);
                    protect.setReceiveAccountBalance(balance.longValue());
                } else if (protect.getType() != null && protect.getType() == 0) {
                    protect.setReceiveAccountBalance(null);
                }
                protectRecordDao.insertOldScore(protect);
            }
        }
    }

    @Override
    public void updateIsEnd(String orderSn, Integer isEnd) {
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("orderSn", orderSn);
        param.put("isEnd", isEnd);
        protectRecordDao.updateIsEnd(param);
    }

    /**
     * 退款成功，修改订单表，订单商品表，结算中心表(退款状态和endTime)，冻结余额
     *
     * @param orderSn
     * @param orgId
     * @param recId
     */
    @Override
    public void overAction(String orderSn, String orgId, Long recId) {
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("orderSn", orderSn);
        param.put("recId", recId);
        param.put("refundStatus", 6);
        //修改订单商品表退款状态
        protectRecordDao.updateOrderGoodsStatus(param);
        //修改结算中心该退款状态（完成）
        param.put("protectStatus", 2);
        //查询有没有申请退款中记录
        Integer counts = protectRecordDao.getOneCount(param);
        if (counts > 0) {
            //更新申请中
            protectRecordDao.updateProtectStatus(param);
        } else {
            //更新拒绝的
            protectRecordDao.updateProtectStatusE(param);
        }

        //查询退款列表，扣除冻结余额
        List<ProtectPo> protectList = protectRecordDao.getRefundList(param);
        if (protectList != null && protectList.size() > 0) {
            for (ProtectPo protect : protectList) {
                if (!protect.getType().equals(TradeTypeConstants.TRADE_SERVER_FEE)
                        & !protect.getType().equals(TradeTypeConstants.REJUVENATE_FEE)
                        & !protect.getType().equals(TradeTypeConstants.PURCHASE_FEE)
                        & !protect.getType().equals(TradeTypeConstants.SPREAD_FEE)) {
                    //交易手续费,返润佣金,采购要减,推广佣金（冻结金额没有加，所以不用减）
                    reduceFreeze(protect);
                }
            }
        }
        //查询订单还有没有退款中订单商品
        Integer count = protectRecordDao.getOtherRefundCount(param);
        if (count == 0) {
            //所有退款完成
            //1更改订单退款状态
            param.put("refundState", 3);
            protectRecordDao.updateOrderRefundState(param);

            //获取0未申请退款  7退款失败的个数
            Integer overcount = protectRecordDao.getOverCount(param);
            if (overcount != null && overcount == 0) {
                Integer freezeTime = protectRecordDao.getfreezeTime(orgId);
                param.put("freezeTime", freezeTime);
                //结算中心（endTime）
                protectRecordDao.updateEndTime(param);
                protectRecordDao.updateOrderEndTime(param);
                //没有则修改订单状态30变为40（已完成）
                protectRecordDao.updateStatusConfirm(param);
                //没有则修改订单状态20变为0（已取消）
                protectRecordDao.cancelStatusConfirm(param);
            } else {
                //查询订单是否完结
                Integer orderState = protectRecordDao.getOrderState(param);
                //订单完结则解冻
                if (orderState == 40) {
                    //结算中心（endTime）
                    Integer freezeTime = protectRecordDao.getfreezeTime(orgId);
                    param.put("freezeTime", freezeTime);
                    protectRecordDao.updateEndTime(param);
                    protectRecordDao.updateOrderEndTime(param);
                } else if (orderState == 20) {
                    //如果大于0，查询没有发货的商品个数
                    Integer notDelivercount = protectRecordDao.getNotDeliverCount(param);
                    if (notDelivercount != null && notDelivercount == 0) {
                        //没有则修改订单状态20变为30（待收货）
                        protectRecordDao.deliverStatusConfirm(param);
                    }
                }

            }
        }

    }

    /**
     * 退款扣除冻结金额
     *
     * @param : Protect 退款的记录
     */
    @Override
    public void reduceFreeze(ProtectPo protect) {
        //获取付款用户
        String to = protect.getPayUser();
        //获取收款用户
        String receiveUser = protect.getReceiveUser();
        Integer payRole = protect.getPayRole();
        Long amount = protect.getAmount();
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("to", to);
        param.put("amount", amount);
        param.put("receiveUser", receiveUser);
        //1是现金 2 金币
        if ((protect.getAmountType() != null && protect.getAmountType() == 1) ||
                (protect.getAmountType() != null && protect.getAmountType() == 2 &&
                        protect.getType() != null && protect.getType() == 0)) {
            switch (payRole) {
                // 根据付款人角色，判断给哪个表扣除
                case 0:
                    break;
                case 1:
                    // 大b
                    protectRecordDao.reduceFreezeByOrgId(param);
                    break;
                case 2:
                    // 小b
                    protectRecordDao.reduceFreezeBySaleCustomerId(param);
                    stringRedisTemplate.delete("home:customer_info_" + to);
                    break;
                case 3:
                case 4:
                case 5:
                    // 普通用户
                    protectRecordDao.reduceFreezeByUserCustomerId(param);
                    stringRedisTemplate.delete("home:customer_info_" + to);
                    break;
                default:
                    break;
            }
        }

        if (protect.getAmountType() != null && protect.getAmountType() == 2) {
            if (protect.getType() != null && protect.getType() != 0) {
                //减去冻结金币
                protectRecordDao.reduceCustomerScoreFreezeByCustomerId(param);
                Map<String, Object> scoreLog = new HashMap<>();
                scoreLog.put("customerId", to);
                scoreLog.put("score", amount);
                scoreLog.put("type", 3);
                scoreLog.put("orderSn", protect.getOrderSn());
                scoreLog.put("recId", protect.getRecId());
                purchaseProcessDao.addScoreLog(scoreLog);
            }
            //还给用户金币
            if (protect.getType() != null && protect.getType() == 0) {
                protectRecordDao.addCustomerScoreFreezeByCustomerId(param);
                Map<String, Object> scoreLog = new HashMap<>();
                scoreLog.put("customerId", receiveUser);
                scoreLog.put("score", amount);
                scoreLog.put("type", 2);
                scoreLog.put("orderSn", protect.getOrderSn());
                scoreLog.put("recId", protect.getRecId());
                purchaseProcessDao.addScoreLog(scoreLog);
            }

        }
    }

    /**
     * 退款失败，修改订单表，订单商品表，结算中心表(退款状态和endTime)
     *
     * @param orderSn
     * @param orgId
     * @param recId
     * @param refundStatus 7或0
     */
    @Override
    public void revokeAction(String orderSn, String orgId, Long recId, Integer refundStatus) {
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("orderSn", orderSn);
        param.put("recId", recId);
        param.put("refundStatus", refundStatus);
        //修改订单商品表退款状态
        protectRecordDao.updateOrderGoodsStatus(param);
        if (refundStatus == 0) {
            //修改结算中心该退款状态(撤销)
            param.put("protectStatus", 3);
            protectRecordDao.updateProtectStatus(param);
        }
        //查询订单还有没有退款中订单商品
        Integer count = protectRecordDao.getOtherRefundCount(param);
        if (count == 0 && refundStatus == 0) {
            //所有退款完成
            //1更改订单退款状态
            param.put("refundState", 3);
            protectRecordDao.updateOrderRefundState(param);
            //获取其他0未申请退款
            Integer overcount = protectRecordDao.getOverCount(param);
            if (overcount != null && overcount == 0) {
                //结算中心（endTime）
                Integer freezeTime = protectRecordDao.getfreezeTime(orgId);
                param.put("freezeTime", freezeTime);
                protectRecordDao.updateEndTime(param);
                protectRecordDao.updateOrderEndTime(param);
            } else if (overcount != null && overcount > 0) {
                //查询订单是否完结
                Integer orderState = protectRecordDao.getOrderState(param);
                //订单完结则解冻
                if (orderState == 40) {
                    //结算中心（endTime）
                    Integer freezeTime = protectRecordDao.getfreezeTime(orgId);
                    param.put("freezeTime", freezeTime);
                    protectRecordDao.updateEndTime(param);
                    protectRecordDao.updateOrderEndTime(param);
                }
            }
        }
    }

    @Override
    public Integer getOtherOrderSnList(String orderSn) {
        return protectRecordDao.getOtherOrderSnList(orderSn);
    }

    @Override
    public void updateOrderIsEnd(String orderSn, Integer isEnd) {
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("orderSn", orderSn);
        param.put("isEnd", isEnd);
        protectRecordDao.updateOrderIsEnd(param);
    }

    @Override
    public void doneVipOrder(String orderSn) {
        protectRecordDao.doneVipOrder(orderSn);
    }

    @Override
    public void updateIntegralOrderIsEnd(String orderSn, int isEnd) {
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("orderSn", orderSn);
        param.put("isEnd", isEnd);
        protectRecordDao.updateIntegralOrderIsEnd(param);
    }
}
